package com.df.gameai.config;

import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import dev.langchain4j.web.search.searchapi.SearchApiWebSearchEngine;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class LangchainCfg {

    @Value("${langchain4j.open-ai.chat-model.api-key}")
    private String apiKey;
    @Value("${langchain4j.open-ai.chat-model.model-name}")
    private String modelName;
    @Value("${langchain4j.open-ai.chat-model.base-url}")
    private String baseUrl;

//    @Bean
//    public ChatLanguageModel chatLanguageModel(){
//        return OpenAiChatModel.builder()
//                .apiKey(apiKey)
//                .modelName(modelName)
//                .baseUrl(baseUrl)
//                .strictJsonSchema(true)
////                .maxTokens(4096)
//                .maxTokens(8192)
//                .temperature(1d)
//                .build();
//    }

    @Qualifier
    @Bean
    public StreamingChatLanguageModel streamingChatLanguageModel(){
        return OpenAiStreamingChatModel.builder()
                .apiKey(apiKey)
                .modelName(modelName)
                .baseUrl(baseUrl)
                .strictJsonSchema(true)
//                .maxTokens(4096)
                .maxTokens(8192)
                .temperature(1d)
                .build();
    }

    @Bean
    public OpenAiStreamingChatModel OpenAiStreamingChatModel(){
        return OpenAiStreamingChatModel.builder()
                .apiKey(apiKey)
                .modelName(modelName)
                .baseUrl(baseUrl)
                .strictJsonSchema(true)
//                .maxTokens(4096)
                .maxTokens(8192)
                .temperature(1d)
                .build();
    }
//    @Bean
//    public SearchApiWebSearchEngine  searchApiWebSearchEngine(){
//        SearchApiWebSearchEngine searchEngine = SearchApiWebSearchEngine.builder()
//                .apiKey(SEARCHAPI_API_KEY)
//                .engine("Bing")
//                .optionalParameters(optionalParameters)
//                .build();
//        return searchEngine;
//    }
}
